<cfsetting enablecfoutputonly="true">
<!--- Make sure all content to be outputed is wrapped in <cfoutput></cfoutput> tags. --->
<cfswitch expression="#thisTag.executionMode#">
	<cfcase value="start">
		<cfparam name="attributes.id" default="">
		<cfparam name="attributes.data" default="">
		<cfparam name="attributes.displayField" default="display">
		<cfparam name="attributes.idField" default="id">
		<cfparam name="attributes.rightField" default="tree_left">
		<cfparam name="attributes.leftField" default="tree_left">
		<cfparam name="attributes.topicField" default="topic">
		<cfparam name="attributes.renderModule" default="">
		<cfparam name="attributes.renderPath" default="">
		<cfparam name="attributes.wrapElement" default="ul">
		<cfparam name="attributes.listItems" default="">
		<cfset attributes.delimiters = ",">
		<cfif StructKeyExists(caller,'root')>
			<cfset root = caller.root>
		<cfelse>
			<cfset root = caller>
		</cfif>
		<cfif NOT thisTag.hasEndTag>
			<cfthrow detail="End tag required" message="All coop tags require an end tag." errorcode="sos.tag.attributes">
		</cfif>
		<cfif attributes.id EQ ''>
			<cfthrow detail="Missing required attribute: 'id'" message="'id' attribute is required">
		</cfif>
		<cfscript>
		standardattributes = 'id,delimiters,listItems,wrapElement,data,renderModule,renderPath'; // internally handled attributes
		attributes = root.coop.mergeattributes(attributes,root);
		attributeList = root.coop.createAttributeList(attributes,standardAttributes,root);
		if (attributes.renderPath EQ '') {
			attributes.renderPath = root.coop.get_sharePath() & 'tags/coop/renderers/';
		}
	</cfscript>
	</cfcase>
	<cfcase value="end">
		<!--- Head Content --->
		<!--- This is where you include any content that will be included in the head of your document --->
		<cfsaveContent variable="myJSScriptBlock">
			<!--- Include your javascript here and make sure it is wrapped with the following code: <cfoutput><script></script></cfoutput> --->
		</cfsaveContent>
		<cfsaveContent variable="myCSSBlock">
			<!--- Include your CSS here and make sure it is wrapped with the following code: <cfoutput><style></style></cfoutput> --->
		</cfsaveContent>
		<cfscript>
		/* *** Sample Entries ***
		root.coop.sosContent.addHeadContent(type:"js",src:"path/to/js file");
		root.coop.sosContent.addHeadContent(type:"js",content:"#myJSScriptBlock#");
		root.coop.sosContent.addHeadContent(type:"css",src:"path/to/CSS file");
		root.coop.sosContent.addHeadContent(type:"css",content:"#myCSSBlock#");
		 */
		</cfscript>
		<!--- pre content markup / code --->
		<cfscript>
		// Check to see if data is simple value and allow it to be passed in as generated content
		if (isSimpleValue(attributes.data) AND attributes.data EQ ''){
			attributes.data = thisTag.generatedContent;
			thisTag.generatedContent = '';
		}
		// Initialize the returnData object that we use for data handling
		returnData = createObject("component","#root.coop.get_shareClassPath()#objects.coop.returnData").init(attributes.data,attributes.delimiters);
		
		// get the number of records in the data passed into the returnData object
		recordCount = returnData.recordCount();
		// Remove any externally generated content.
		thisTag.generatedContent = '';
		
		// optional : start markup / code (outside data loop)
		writeOutput('<#attributes.wrapElement# id="#attributes.id#"#attributeList#>');
		// Loop through your data
		</cfscript>
		<cfset rendererAttributes = structNew()>
		<cfset rendererAtributes.listItems = attributes.listItems>
		<cfloop from = "1" to = "#recordCount#" index="iRow">
			<cfscript>
				currentRow = returnData.returnDataRowStruct(iRow);
				rendererAttributes.data = currentRow;
			</cfscript>
			<cfoutput><cfmodule template="#attributes.renderPath##attributes.renderModule#.cfm" attributeCollection="#rendererAttributes#"></cfoutput>
		</cfloop>
		<!--- for(iRow=1; iRow LTE recordCount; iRow = iRow + 1) {
			currentRow = returnData.returnDataRowStruct(iRow);
			writeOutput(attributes.renderObject.renderRow(currentRow));
		} --->
		<cfscript>
		// optional : end markup / code (outside data loop)
		writeOutput('</#attributes.wrapElement#>');
		</cfscript>
		<!--- pre content markup / code --->
		<cfoutput>#thisTag.generatedContent#</cfoutput>
		<!--- post content markup / code --->
	</cfcase>
</cfswitch>
<cfsetting enablecfoutputonly="false">
<cffunction name="buildTree" output="false">
    	<cfargument name="treeData">
        
       	<cfset var right = arrayNew(1)>
		<cfset var currentParent = ''>
		<cfset var tree = ''>
        <cfsaveContent variable="tree">
        
<ul>
<cfloop query="attributes.treeData">

    	<cfoutput>
   <!--- only check stack if there is one --->
   <cfif arrayLen(right)>
	   <!--- check if we should remove a node from the stack --->
	   <cfloop condition="right[arrayLen(right)] LTE tree_right">
       		<cfif listLast(currentParent) EQ right[arrayLen(right)]>
            	<cfset currentParent = listDeleteAt(currentParent,listLen(currentParent))>
            	</ul></li>
			<cfelse>
   
   <cfif currentRow-1>
   	</li>
   </cfif>
            </cfif>
		   <cfset arrayDeleteAt(right,arrayLen(right))>
	   </cfloop>
   </cfif>
   
   <!--- display indented node5 title--->
   <li>
       #post_body#&nbsp;
		
	<cfif currentRow EQ attributes.treeData.recordCount>
    	</li>
        <cfloop list="#currentParent#" index="iParent">
     </ul>
        </cfloop>
    </cfif>
	<cfif tree_right - tree_left GT 1>
    	<cfset currentParent = listAppend(currentParent,tree_right)><ul class="coopLabeledField">
    </cfif>
   <cfset arrayAppend(right,tree_right)></cfoutput>
</cfloop>
</ul> 
        </cfsaveContent>
        
        <cfreturn tree>
</cffunction>